﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class Templates_mwc_template_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            string login_name = Page.Request.Form["login_name"];
            string password = Page.Request.Form["password"];
            bool my_flag = false;
            string conn = ConfigurationSettings.AppSettings["mwc_con"];
            string query = "SELECT * FROM mwc_user WHERE name =  '" + login_name + "' AND password = '" + password + "' AND enable = 1";
            SqlConnection scn = new SqlConnection(conn);
            SqlCommand scmd = new SqlCommand(query, scn);
            scn.Open();
            SqlDataReader sdr = scmd.ExecuteReader();
            try {
                while (sdr.Read()) {
                    my_flag = true;
                }
            }
            finally {
                sdr.Close();
            }
            mwc_submit.Text = my_flag.ToString();
            
            if (my_flag == true)
            {
                Session.Add("Autorized", 1);
                Session.Add("UserName",login_name);

                Response.Redirect("~/mwc_admin/Panel.aspx");
            }

        }
    }
}
